bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_java", version = "8.6.0")
bazel_dep(name = "rules_jvm_external", version = "6.7")
bazel_dep(name = "rules_android", version = "0.6.0")
bazel_dep(name = "rules_kotlin", version = "2.1.9", repo_name = "io_bazel_rules_kotlin")
bazel_dep(name = "rules_robolectric", version = "4.14.1.2", repo_name = "robolectric")
bazel_dep(name = "protobuf", version = "29.0", repo_name = "com_google_protobuf")

# Pin the version of rules_robolectric so that it matches the robolectric version we get from maven.
single_version_override(
    module_name = "rules_robolectric",
    version = "4.14.1.2",
)

# Setup the Android SDK repository
android_sdk_repository_extension = use_extension(
    "@rules_android//rules/android_sdk_repository:rule.bzl",
    "android_sdk_repository_extension",
)
android_sdk_repository_extension.configure(api_level = 34)
use_repo(android_sdk_repository_extension, "androidsdk")

register_toolchains("@androidsdk//:sdk-toolchain", "@androidsdk//:all")

# Define the versions of the maven dependencies we use.

ANDROID_LINT_VERSION = "30.3.1"

ANT_VERSION = "1.9.6"

ASM_VERSION = "9.8"

AUTO_COMMON_VERSION = "1.2.1"

BYTE_BUDDY_VERSION = "1.9.10"

CHECKER_FRAMEWORK_VERSION = "2.5.3"

ECLIPSE_SISU_VERSION = "0.3.0"

ERROR_PRONE_VERSION = "2.23.0"

GUAVA_VERSION = "33.0.0"

GRPC_VERSION = "1.2.0"

INCAP_VERSION = "0.2"

KOTLIN_VERSION = "2.2.20"

KSP_VERSION = KOTLIN_VERSION + "-2.0.3"

MAVEN_VERSION = "3.3.3"

ROBOLECTRIC_VERSION = "4.14.1"

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")

# Test only maven dependencies
[
    maven.artifact(
        testonly = True,
        artifact = artifact,
        group = group,
        version = version,
    )
    for group, artifact, version in [coord.split(":") for coord in [
        "androidx.test:monitor:1.4.0",
        "androidx.test:core:1.4.0",
        "androidx.test.ext:junit:1.1.3",
        "com.android.tools.lint:lint-tests:%s" % ANDROID_LINT_VERSION,
        "com.android.tools:testutils:%s" % ANDROID_LINT_VERSION,
        "com.google.guava:guava-testlib:%s-jre" % GUAVA_VERSION,
        "com.google.testing.compile:compile-testing:0.18",
        "com.google.truth.extensions:truth-java8-extension:1.4.0",
        "com.google.truth:truth:1.4.0",
        "javax.inject:javax.inject-tck:1",
        "org.hamcrest:hamcrest-core:1.3",
        "org.mockito:mockito-core:5.4.0",
        "org.robolectric:robolectric:%s" % ROBOLECTRIC_VERSION,
        "org.robolectric:shadows-framework:%s" % ROBOLECTRIC_VERSION,  # For ActivityController
    ]]
]

# Forced versions of maven dependencies
[
    maven.artifact(
        artifact = artifact,
        force_version = True,
        group = group,
        version = version,
    )
    for group, artifact, version in [coord.split(":") for coord in [
        "com.google.guava:guava:%s-jre" % GUAVA_VERSION,
    ]]
]

maven.install(
    artifacts = [
        "androidx.annotation:annotation:1.7.1",
        "androidx.annotation:annotation-experimental:1.3.1",
        "androidx.appcompat:appcompat:1.3.1",
        "androidx.activity:activity:1.5.1",
        "androidx.fragment:fragment:1.5.1",
        "androidx.lifecycle:lifecycle-common:2.5.1",
        "androidx.lifecycle:lifecycle-viewmodel:2.5.1",
        "androidx.lifecycle:lifecycle-viewmodel-savedstate:2.5.1",
        "androidx.multidex:multidex:2.0.1",
        "androidx.navigation:navigation-common:2.5.1",
        "androidx.navigation:navigation-fragment:2.5.1",
        "androidx.navigation:navigation-runtime:2.5.1",
        "androidx.savedstate:savedstate:1.2.0",
        "com.android.support:appcompat-v7:25.0.0",
        "com.android.support:support-annotations:25.0.0",
        "com.android.support:support-fragment:25.0.0",
        "com.android.tools.external.org-jetbrains:uast:%s" % ANDROID_LINT_VERSION,
        "com.android.tools.external.com-intellij:intellij-core:%s" % ANDROID_LINT_VERSION,
        "com.android.tools.external.com-intellij:kotlin-compiler:%s" % ANDROID_LINT_VERSION,
        "com.android.tools.lint:lint:%s" % ANDROID_LINT_VERSION,
        "com.android.tools.lint:lint-api:%s" % ANDROID_LINT_VERSION,
        "com.android.tools.lint:lint-checks:%s" % ANDROID_LINT_VERSION,
        "com.google.auto:auto-common:%s" % AUTO_COMMON_VERSION,
        "com.google.auto.factory:auto-factory:1.0",
        "com.google.auto.service:auto-service:1.0",
        "com.google.auto.service:auto-service-annotations:1.0",
        "com.google.auto.value:auto-value:1.9",
        "com.google.auto.value:auto-value-annotations:1.9",
        "com.google.code.findbugs:jsr305:3.0.1",
        "com.google.devtools.ksp:symbol-processing:%s" % KSP_VERSION,
        "com.google.devtools.ksp:symbol-processing-api:%s" % KSP_VERSION,
        "com.google.devtools.ksp:symbol-processing-common-deps:%s" % KSP_VERSION,
        "com.google.devtools.ksp:symbol-processing-aa-embeddable:%s" % KSP_VERSION,
        "com.google.errorprone:error_prone_annotation:%s" % ERROR_PRONE_VERSION,
        "com.google.errorprone:error_prone_annotations:%s" % ERROR_PRONE_VERSION,
        "com.google.errorprone:error_prone_check_api:%s" % ERROR_PRONE_VERSION,
        "com.google.googlejavaformat:google-java-format:1.33.0",
        "com.google.guava:failureaccess:1.0.1",
        "com.google.guava:guava-beta-checker:1.0",
        "com.google.protobuf:protobuf-java:4.29.3",
        "com.squareup:javapoet:1.13.0",
        "com.squareup:kotlinpoet:1.11.0",
        "com.squareup:kotlinpoet-javapoet:1.11.0",
        "io.github.java-diff-utils:java-diff-utils:4.11",
        "io.grpc:grpc-context:%s" % GRPC_VERSION,
        "io.grpc:grpc-core:%s" % GRPC_VERSION,
        "io.grpc:grpc-netty:%s" % GRPC_VERSION,
        "io.grpc:grpc-protobuf:%s" % GRPC_VERSION,
        "jakarta.inject:jakarta.inject-api:2.0.1",
        "javax.annotation:javax.annotation-api:1.3.2",
        "javax.enterprise:cdi-api:1.0",
        "javax.inject:javax.inject:1",
        "junit:junit:4.13.2",
        "net.bytebuddy:byte-buddy:%s" % BYTE_BUDDY_VERSION,
        "net.bytebuddy:byte-buddy-agent:%s" % BYTE_BUDDY_VERSION,
        "net.ltgt.gradle.incap:incap:%s" % INCAP_VERSION,
        "net.ltgt.gradle.incap:incap-processor:%s" % INCAP_VERSION,
        "org.apache.ant:ant:%s" % ANT_VERSION,
        "org.apache.ant:ant-launcher:%s" % ANT_VERSION,
        "org.apache.maven:maven-artifact:%s" % MAVEN_VERSION,
        "org.apache.maven:maven-model:%s" % MAVEN_VERSION,
        "org.apache.maven:maven-plugin-api:%s" % MAVEN_VERSION,
        "org.checkerframework:checker-compat-qual:%s" % CHECKER_FRAMEWORK_VERSION,
        "org.checkerframework:dataflow:%s" % CHECKER_FRAMEWORK_VERSION,
        "org.checkerframework:javacutil:%s" % CHECKER_FRAMEWORK_VERSION,
        "org.codehaus.plexus:plexus-utils:3.0.20",
        "org.codehaus.plexus:plexus-classworlds:2.5.2",
        "org.codehaus.plexus:plexus-component-annotations:1.5.5",
        "org.eclipse.sisu:org.eclipse.sisu.plexus:%s" % ECLIPSE_SISU_VERSION,
        "org.eclipse.sisu:org.eclipse.sisu.inject:%s" % ECLIPSE_SISU_VERSION,
        "org.jetbrains.kotlin:kotlin-annotation-processing-embeddable:%s" % KOTLIN_VERSION,
        "org.jetbrains.kotlin:kotlin-compiler-embeddable:%s" % KOTLIN_VERSION,
        "org.jetbrains.kotlin:kotlin-daemon-embeddable:%s" % KOTLIN_VERSION,
        "org.jetbrains.kotlin:kotlin-metadata-jvm:%s" % KOTLIN_VERSION,
        "org.jetbrains.kotlin:kotlin-stdlib:%s" % KOTLIN_VERSION,
        "org.jspecify:jspecify:1.0.0",
        "org.pantsbuild:jarjar:1.7.2",
        "org.objenesis:objenesis:1.0",
        "org.ow2.asm:asm:%s" % ASM_VERSION,
        "org.ow2.asm:asm-tree:%s" % ASM_VERSION,
        "org.ow2.asm:asm-commons:%s" % ASM_VERSION,
    ],
    fail_if_repin_required = True,
    lock_file = "//:maven_install.json",
    repositories = [
        "https://repo1.maven.org/maven2",
        "https://maven.google.com",
    ],
)
use_repo(maven, "maven")
